package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 日报
 */
@Getter
@Setter
@ToString
public class News extends BaseDomain{
    public static final Integer STATE_SAVE=0;//草稿
    public static final Integer STATE_RELEASE =1;//发布
    public static final Integer STATE_HOT =2;//推荐
    public static final Integer STATE_DISABLE =-1;//禁用


    //标题
    private String title;
    //副标题
    private String subTitle;
    //创建时间
    private Date createTime;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;
    //状态
    private Integer state;
    //背景
    private String coverUrl;
    //收藏数量
    private Integer collectionNum;
    //点赞数量
    private Integer likeNum;
    //查看数量
    private Integer browseNum;
    //文章内容
    private NewsContent newsContent;

    public String getStateName(){
        String stateName="发布";
        if (STATE_SAVE.equals(state)){
            stateName="草稿";
        }else if(STATE_HOT.equals(state)){
            stateName="推荐";
        }else if(STATE_DISABLE.equals(state)){
            stateName="禁用";
        }
        return stateName;
    }

    public Object getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        if (newsContent != null) {
            map.put("newsContent",newsContent.getContent());
            map.put("newsContentId",newsContent.getId());
        }
        return JSONUtil.toJSONString(map);
    }
}